package search;
/*顺序查找
* des 要查找的元素
* i 保存当前元素的下标
*/
public class OrderSearch {
public static int ordersearch(int[] arry,int des){
int i=0;
for(;i<=arry.length-1;i++){
if(des==arry[i])
return i;
}
return -1;
}
public static void main(String[] args){
int[] a=new int[]{2,3,5,6,7,3,};
System.out.println(ordersearch(a,3));
}
}
C实现算法
int sq_search(keytype keyp[],int n,keytype key)
{
int i;
for(i=0; i<n; i++)
if(key[i] == key)
return i;//查找成功
return -1;//查找失败
}


function bubbleSort(arr) {
    var i = arr.length, j;
    var tempExchangVal;
    while (i > 0) {
        for (j = 0; j < i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                tempExchangVal = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = tempExchangVal;
            }
        }
        i--;
    }
    return arr;
}
 
var arr = [3, 2, 4, 9, 1, 5, 7, 6, 8];
var arrSorted = bubbleSort(arr);
console.log(arrSorted);
alert(arrSorted);
控制台将输出：[1, 2, 3, 4, 5, 6, 7, 8, 9]
并且弹窗；



public class BubbleSort
{
    public void sort(int[] a)
    {
        int temp = 0;
        for (int i = a.length - 1; i > 0; --i)
        {
            for (int j = 0; j < i; ++j)
            {
                if (a[j + 1] < a[j])
                {
                    temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
    }
}

public static int binarySearch(Integer[] srcArray, int des) {
    int low = 0;
    int high = srcArray.length - 1;
 
    while ((low <= high) && (low <= srcArray.length - 1)
            && (high <= srcArray.length - 1)) {
        int middle = (high + low) >> 1;
        if (des == srcArray[middle]) {
            return middle;
        } else if (des < srcArray[middle]) {
            high = middle - 1;
        } else {
            low = middle + 1;
        }
    }
    return -1;
}




varArr=[3,5,6,7,9,12,15];
functionbinary(find,arr,low,high){
if(low<=high){
if(arr[low]==find)
returnlow;
if(arr[high]==find)
returnhigh;
varmid=Math.ceil((high+low)/2);
if(arr[mid]==find){
returnmid;
}elseif(arr[mid]>find){
returnbinary(find,arr,low,mid-1);
}else{
returnbinary(find,arr,mid+1,high);
}
}
return-1;
}
binary(15,Arr,0,Arr.length-1);





<script>
function MyClass(){
  this.a = '2';//可以通过this定义属性
}
MyClass.prototype.say= function () { //扩充方法
   return 'hello'; 
}
MyClass.prototype.mValue= '3';//扩充属性
 
var mc = new MyClass();
alert(mc.a);
alert(mc.say());
alert(mc.mValue);
</script>